﻿namespace CodedUISample.StepDefinitions.Context
{
    using System;

    using UITest.Selenium.WebDrivers;

    /// <summary>
    ///     The example page context factory.
    /// </summary>
    public class SeleniumSamplePageContextFactory : IDisposable
    {
        #region Static Fields

        private static readonly SeleniumSamplePageContextFactory Instance = new SeleniumSamplePageContextFactory();

        #endregion

        #region Fields

        private SeleniumSamplePageContext _context;

        #endregion

        #region Constructors and Destructors

        private SeleniumSamplePageContextFactory()
        {
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///     Gets the factory.
        /// </summary>
        public static SeleniumSamplePageContextFactory Factory
        {
            get
            {
                return Instance;
            }
        }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        ///     The dispose.
        /// </summary>
        public void Dispose()
        {
            this._context = null;
        }

        /// <summary>
        /// The get context.
        /// </summary>
        /// <returns>
        /// The <see cref="SeleniumSamplePageContext"/>.
        /// </returns>
        public SeleniumSamplePageContext GetContext()
        {
            return this._context;
        }

        /// <summary>
        /// The new.
        /// </summary>
        /// <param name="provider">
        /// The provider.
        /// </param>
        public void New(IWebDriverProvider provider = null)
        {
            this.Dispose();
            this._context = new SeleniumSamplePageContext();
        }

      
        #endregion
    }
}